<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="form.nickname" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.username" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院">
              <el-input v-model="form.hospitalAddress" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="测评时间">
              <el-date-picker
                v-model="dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="nickname" label="会员昵称" />
        <el-table-column prop="username" label="会员手机号" >
             <template slot-scope="scope">
            <div>{{scope.row.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="birthday" label="出生年月" />
        <el-table-column prop="sex" label="性别">
          <template slot-scope="scope">{{ scope.row.sex | sexType }}</template>
        </el-table-column>
        <el-table-column prop="hospitalAddress" label="医院信息" />
        <el-table-column prop="createdAt" label="注册时间" />
        <el-table-column prop="recordTime" label="测评时间" />
        <el-table-column
          v-if="hasPermission('AdminUserIdentityAuthProvider.review')"
          fixed="right"
          label="操作"
          width="120"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="toRoutes('plasticReportInfo',scope.row.id)"
            >报告详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.pageNum"
            :page-sizes="page_sizes"
            :page-size="form.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { plasticReportList } from "@/api/plasticReport";

export default {
  name: "plasticReportIndex",
  data() {
    return {
      tableLoading: true,
      form: {
        nickname: null,
        username: null,
        hospitalAddress: null,
        recordTimeStart: null,
        recordTimeEnd: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      dates: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 0
    };
  },
  filters: {
    sexType(e) {
      switch (e) {
        case 0:
          return "保密";
        case 1:
          return "男";
        case 2:
          return "女";
      }
    }
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    // 列表数据获取
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      plasticReportList(datas)
        .then(res => {
          // console.log(res);
          if (!res.data.code) {
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    // 按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    // 路由跳转
    toRoutes(e, userId) {
      const route = { name: e, query: { userId: userId } };
      this.$router.push(route);
    },
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      if (this.dates != null) {
        if (this.dates.length) {
          this.form.recordTimeStart = this.dates[0];
          this.form.recordTimeEnd = this.dates[1];
        }
      } else {
        this.form.recordTimeStart = null;
        this.form.recordTimeEnd = null;
      }
      this.getList(this.form);
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
